/*
 * Copyright (C) 2011-2012 Andrew Wells
 *
 * Licensed under the GNU License, Version 3
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.gnu.org/copyleft/gpl.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * Dungeons & Dragons Copyright (C) Wizards of the Coast. I do not claim
 * the right to any information used from their books or resources.
 */

package com.trace.wells.charactertracker;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.Html;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.AutoCompleteTextView;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnGroupCollapseListener;
import android.widget.ExpandableListView.OnGroupExpandListener;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.SimpleAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class BattleScreen extends Activity {

	private ArrayList<Character> characterList = new ArrayList<Character>();

	Character character;

	int displayMode;
	int returnHealth;
	boolean initMagicInitialized;
	boolean characterUpdateNeeded;

	Spell tempSpell;
	Weapon tempWeapon;

	MenuInflater menuInflator;

	///////////////////////////
	//ViewPager initialization
	MyPagerAdapter adapter;
	ViewPager myPager;

	//////////////////////////////////
	//This block contains all element initializations for the battle Screen_magic view
	//

	////////Level up dialog
	LinearLayout experienceLayout;
	SeekBar levelupSeekBar;
	TextView levelupHitDieTxt;
	TextView levelupAmountTxt;
	Button levelupButton;
	////////

	////////Battle_screen_magic

	LinearLayout swipeLayout;

	LinearLayout healthBoxLayout;
	LinearLayout healthBarLayout;

	ListAdapter spellList;

	ProgressBar healthbar;
	ProgressBar experienceBar;

	TextView currentHealthTxt;//battleMagicHealthCurrent;
	TextView totalHealthTxt;//battleMagicHealthCurrent;

	//Ability Score TextView IDs
	private TextView strTxt; //battlemagicAbilStr
	private TextView dexTxt; //battlemagicAbilDex
	private TextView conTxt; //battlemagicAbilCon
	private TextView intTxt; //battlemagicAbilInt
	private TextView wisTxt; //battlemagicAbilWis
	private TextView chaTxt; //battlemagicAbilCha

	private TextView strModTxt; //battlemagicAbilStrMod
	private TextView dexModTxt; //battlemagicAbilDexMod
	private TextView conModTxt; //battlemagicAbilConMod
	private TextView intModTxt; //battlemagicAbilIntMod
	private TextView wisModTxt; //battlemagicAbilWisMod
	private TextView chaModTxt; //battlemagicAbilChaMod

	private TextView conciousWarnTxt;//battlemagicConciousState

	private TextView armorClassTxt; //battlemagicarmorClass

	private TextView saveFortTxt; //battleagicFortSave
	private TextView saveReflexTxt; //battlemagicRefSave
	private TextView saveWillTxt; //battlemagicWillSave

	private TextView experienceTxt;//battlemagicExpCurrent
	private TextView baseExpTxt;//battlemagicExplevelBase
	private TextView maxExpTxt;//battlemagicExplevelMax
	private TextView currentLevelTxt;//battlemagicCurrentLevel

	private boolean manualHealthEntry;
	////////

	//
	//
	//////////////////////////////////

	//////////////////////////////////
	//This block contains all element initializations for the magic_spells_menu view
	//

	//This variable is used to determine which spell book to load when the user swipes their finger to switch views.
	//It helps swipe from spellbook to spellbook, other to Spellbook, and spellbook to other..
	int currentSpellBookView;

	private TextView spellsTitleText;

	ArrayList<Map<String, String>> spellStringArrayList;
	private Spinner classSelectionSpinner;
	private SpellExpandableListAdapter spellListAdapter;
	private ExpandableListView list;
	private ExpandableListView fillerList;
	private LayoutInflater inflater;
	private AutoCompleteTextView acTextView;
	private LinearLayout magicLinearLayout;

	///////Objects for Add Spell dialog
	private Button addSpellDoneButton;
	private TextView spellInformaion;

	//
	//
	//////////////////////////////////

	//////////////////////////////////
	//This block contains all element initializations for the weapon_screen view
	//

	public LinearLayout activeWeaponLinear;
	public ListView weaponListView;
	public WeaponListCustomAdapter weaponAdapter;

	private LayoutInflater weaponInflatr;

	private AutoCompleteTextView weaponDialogAcTextView;

	private TextView weaponDialogName;
	private TextView weaponDialogType;
	private TextView weaponDialogDamage;
	private TextView weaponDialogCritical;
	private TextView weaponDialogRange;
	private TextView weaponDialogWeight;
	private TextView weaponDialogCost;

	private TextView weaponScreenName;
	private TextView weaponScreenAttack;
	private TextView weaponScreenDamage;
	private TextView weaponScreenCritical;
	private TextView weaponScreenRange;
	private TextView weaponScreenWeight;

	private Button weaponDialogAddButton;
	private ArrayList<Map<String, String>> weaponStringArrayList;

	//
	//
	//////////////////////////////////

	//////////////////////////////////
	//Contains all element initialization for item_Screen view
	//

	ExpandableListView itemListView;
	ItemAdapter itemAdapter;

	//This prevents the device from changing orientation when the phone is turned sideways
	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		super.onConfigurationChanged(newConfig);
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Intent data = getIntent();

		Bundle myResults = data.getExtras();

		character = (Character) myResults.get("character");

		currentSpellBookView = character.characterClass.getNextSpellBookLowToHigh(0, character.characterClass.getCharacterClassLevelsArray());

		displayMode = ConstantHelper.DISPLAY_MODE_BATTLE_SCREEN;
		setContentView(R.layout.blank);

		adapter = new MyPagerAdapter();
		myPager = (ViewPager) findViewById(R.id.panelpager);
		myPager.setAdapter(adapter);

		myPager.setCurrentItem(1);
		//initBattleScreen();

		myPager.setOnPageChangeListener(new OnPageChangeListener() {

			@Override
			public void onPageSelected(int arg0) {
				//If currently on battleScreen
				if (character.getOverallMagicType() == ConstantHelper.CHAR_TYPE_MAGIC) {
					if (arg0 == 0) {
						displayMode = ConstantHelper.DISPLAY_MODE_ITEMS;
					}
					if (arg0 == 1) {
						displayMode = ConstantHelper.DISPLAY_MODE_BATTLE_SCREEN;
					}
					if (arg0 == 2) {
						displayMode = ConstantHelper.DISPLAY_MODE_SPELLS;
					}
					if (arg0 == 3) {
						displayMode = ConstantHelper.DISPLAY_MODE_WEAPONS;
					}
				} else {
					if (arg0 == 0) {
						displayMode = ConstantHelper.DISPLAY_MODE_ITEMS;
					}
					if (arg0 == 1) {
						displayMode = ConstantHelper.DISPLAY_MODE_BATTLE_SCREEN;
					}
					if (arg0 == 2) {
						displayMode = ConstantHelper.DISPLAY_MODE_WEAPONS;
					}
				}
			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onPageScrollStateChanged(int arg0) {
				// TODO Auto-generated method stub

			}
		});
	}

	@Override
	public boolean onPrepareOptionsMenu(Menu menu) {
		adapter.notifyDataSetChanged();
		if (character.getOverallMagicType() == ConstantHelper.CHAR_TYPE_MAGIC) {
			switch (displayMode) {
			case ConstantHelper.DISPLAY_MODE_ITEMS:
				menu.clear();
				menu.add(0, ConstantHelper.MENU_BUTTON_ITEMS, 0, "Add Item").setIcon(R.drawable.ic_menu_add_item);
				break;
			case ConstantHelper.DISPLAY_MODE_BATTLE_SCREEN:
				menu.clear();
				menu.add(0, ConstantHelper.MENU_BUTTON_WEAPONS, 0, "Weapons").setIcon(R.drawable.plus);
				menu.add(0, ConstantHelper.MENU_BUTTON_SPELLS, 0, "Spells").setIcon(R.drawable.minus);
				break;
			case ConstantHelper.DISPLAY_MODE_SPELLS:
				menu.clear();
				if (character.characterClass.getCharacterMagicType(currentSpellBookView) == ConstantHelper.CHAR_TYPE_SPECIAL_MAGIC) {

					if (character.hasFreeSpellsKnownSlots(currentSpellBookView))
						menu.add(0, ConstantHelper.MENU_BUTTON_ADD_SPELL, 3, "Add Spell").setIcon(R.drawable.plus);
					else
						menu.add(0, ConstantHelper.MENU_BUTTON_ADD_SPELL, 3, "Add Spell").setIcon(R.drawable.plus).setEnabled(false);

					menu.add(0, ConstantHelper.MENU_BUTTON_RESET_SPELLS, 4, "Reset Spells Count").setIcon(R.drawable.ic_menu_sleep);
					menu.add(0, ConstantHelper.MENU_BUTTON_EXPAND, 1, "Expand All").setIcon(R.drawable.ic_menu_expand);
					menu.add(0, ConstantHelper.MENU_BUTTON_CONTRACT, 2, "Collapse All").setIcon(R.drawable.ic_menu_collapse);
				} else { // will be normal magic type
					menu.add(0, ConstantHelper.MENU_BUTTON_PREPARE_SPELLS, 3, "Prepare Spells").setIcon(R.drawable.ic_menu_prepare);
					menu.add(0, ConstantHelper.MENU_BUTTON_RESET_SPELLS, 4, "Reset Spells Count").setIcon(R.drawable.ic_menu_sleep);
					menu.add(0, ConstantHelper.MENU_BUTTON_EXPAND, 1, "Expand All").setIcon(R.drawable.ic_menu_expand);
					menu.add(0, ConstantHelper.MENU_BUTTON_CONTRACT, 2, "Collapse All").setIcon(R.drawable.ic_menu_collapse);
				}
				break;
			case ConstantHelper.DISPLAY_MODE_WEAPONS:
				menu.clear();
				menu.add(0, ConstantHelper.MENU_BUTTON_ADD_WEAPON, 0, "Add Weapon").setIcon(R.drawable.ic_menu_add_weapon);
				break;
			}
		} else {
			switch (displayMode) {
			case ConstantHelper.DISPLAY_MODE_ITEMS:
				menu.clear();
				menu.add(0, ConstantHelper.MENU_BUTTON_ITEMS, 0, "Add Item").setIcon(R.drawable.ic_menu_add_item);
				break;
			case ConstantHelper.DISPLAY_MODE_BATTLE_SCREEN:
				menu.clear();
				menu.add(0, ConstantHelper.MENU_BUTTON_WEAPONS, 0, "TO Weapons").setIcon(R.drawable.plus);
				menu.add(0, ConstantHelper.MENU_BUTTON_SPELLS, 0, "TO Spells").setIcon(R.drawable.minus);
				break;
			case ConstantHelper.DISPLAY_MODE_WEAPONS:
				menu.clear();
				menu.add(0, ConstantHelper.MENU_BUTTON_ADD_WEAPON, 0, "Add Weapon").setIcon(R.drawable.ic_menu_add_weapon);
				break;
			}
		}
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case ConstantHelper.MENU_BUTTON_RESET_SPELLS:

			character.characterClass.resetSpellsRemainingToMax(currentSpellBookView);
			character.characterClass.setHasBeenCastArray(new boolean[10][10]);

			spellListAdapter.setSpellArrays();
			return true;
		case ConstantHelper.MENU_BUTTON_WEAPONS:
			myPager.setCurrentItem(3, true);
			return true;

		case ConstantHelper.MENU_BUTTON_EXPAND:
			for (int i = 0; i < character.characterClass.getMaxSpellLevelForSpecificClass(currentSpellBookView); i++) {
				list.expandGroup(i);
			}
			return true;

		case ConstantHelper.MENU_BUTTON_CONTRACT:
			for (int i = 0; i < character.characterClass.getMaxSpellLevelForSpecificClass(currentSpellBookView); i++) {
				list.collapseGroup(i);
			}
			return true;

		case ConstantHelper.MENU_BUTTON_SPELLS:
			myPager.setCurrentItem(2, true);
			return true;

		case ConstantHelper.MENU_BUTTON_PREPARE_SPELLS:
			Bundle extras = new Bundle();
			extras.putSerializable("character", character);
			extras.putInt("currentView", currentSpellBookView);

			Intent i = new Intent(BattleScreen.this, PrepareSpells.class);
			i.putExtras(extras);
			startActivityForResult(i, ConstantHelper.REQUEST_CODE_PREPARE_SPELLS);
			return true;

		case ConstantHelper.MENU_BUTTON_ITEMS:
			Log.d("CHAR", "ITEM ADDED! (not really)..");
			return true;

		case ConstantHelper.MENU_BUTTON_ADD_SPELL:

			final Dialog dialog = new Dialog(BattleScreen.this);
			dialog.setContentView(R.layout.spell_selection_dialog);
			dialog.setTitle("Add a Spell");
			dialog.setCancelable(true);

			int[] spellsSlotsAvailable = character.characterClass.getFreeSpellSlotsSpecial(currentSpellBookView);

			//This function gets all the spells that the user can select from based off the number of free slots available to them at their
			//current level.
			spellStringArrayList = ConstantSpellHelper.concatinateSpellLists(spellsSlotsAvailable, ConstantHelper.classIntToString(currentSpellBookView),
					character.characterClass.getMaxSpellLevelForSpecificClass(currentSpellBookView));

			//The adapter that recieves the layout type from android and the array creatd by the above function.
			final SimpleAdapter simpleSpellAdapter = new SimpleAdapter(this, spellStringArrayList, R.layout.spell_selection_item, new String[] { "name", "school", "level" }, new int[] { R.id.spellSelectionItemTxt,
					R.id.spellSelectionItemSchool, R.id.spellSelectionItemLevel });

			acTextView = (AutoCompleteTextView) dialog.findViewById(R.id.spellSelectionAutoCompleteTxt);
			addSpellDoneButton = (Button) dialog.findViewById(R.id.spellSelectionAddButton);
			spellInformaion = (TextView) dialog.findViewById(R.id.spellSelectionInformationTxt);

			addSpellDoneButton.setEnabled(false);

			//The amount of letters is needs before it starts auto completing
			acTextView.setThreshold(1);

			//Set that adapter!
			acTextView.setAdapter(simpleSpellAdapter);

			//acTextView.setFocusableInTouchMode(true);
			acTextView.requestFocus();

			acTextView.setOnItemClickListener(new OnItemClickListener() {

				@Override
				public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

					Map<String, String> tempSpellMap = new HashMap<String, String>();
					tempSpellMap = (Map<String, String>) simpleSpellAdapter.getItem(position);

					FileHelper fh = new FileHelper();
					Spell spell = fh.getSpellInformationBasedOnName(tempSpellMap.get("name"), BattleScreen.this, currentSpellBookView);
					spell.setSpellLevel(Integer.parseInt(tempSpellMap.get("level")));

					StringBuffer sb = new StringBuffer("");
					for (int i = 0; i < spell.getSpellProperties().size(); i++) {
						sb.append(spell.getConcatinatedHtmlProperty(i));
					}
					spellInformaion.setText(Html.fromHtml(sb.toString()));
					tempSpell = spell;

					if (character.spellSlotIsFree(character.getSpecificClassLevel(currentSpellBookView), currentSpellBookView, Integer.parseInt(tempSpellMap.get("level"))))
						addSpellDoneButton.setEnabled(true);
					else
						Toast.makeText(getApplicationContext(), "Level " + tempSpellMap.get("level") + " spell level slots maxed out", Toast.LENGTH_SHORT).show();

					acTextView.setText("");
					InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
					imm.hideSoftInputFromWindow(spellInformaion.getWindowToken(), 0);
				}
			});

			addSpellDoneButton.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					character.spells[currentSpellBookView].add(tempSpell);
					spellListAdapter.setSpellArrays();
					spellListAdapter.notifyDataSetChanged();
					tempSpell = null;
					dialog.cancel();
				}
			});

			dialog.show();

			return true;

		case ConstantHelper.MENU_BUTTON_ADD_WEAPON:

			final Dialog weaponDialog = new Dialog(BattleScreen.this);
			weaponDialog.setContentView(R.layout.weapon_selection_dialog);
			weaponDialog.setTitle("Add a Weapon");
			weaponDialog.setCancelable(true);

			weaponDialogAcTextView = (AutoCompleteTextView) weaponDialog.findViewById(R.id.weaponSelectionAutoCompleteTxt);
			weaponDialogAddButton = (Button) weaponDialog.findViewById(R.id.weaponSelectionAddButton);

			weaponDialogName = (TextView) weaponDialog.findViewById(R.id.weaponDialogName);
			weaponDialogType = (TextView) weaponDialog.findViewById(R.id.weaponDialogType);
			weaponDialogDamage = (TextView) weaponDialog.findViewById(R.id.weaponDialogDamage);
			weaponDialogCritical = (TextView) weaponDialog.findViewById(R.id.weaponDialogCritical);
			weaponDialogRange = (TextView) weaponDialog.findViewById(R.id.weaponDialogRange);
			weaponDialogWeight = (TextView) weaponDialog.findViewById(R.id.weaponDialogWeight);
			weaponDialogCost = (TextView) weaponDialog.findViewById(R.id.weaponDialogCost);

			//This function gets all the spells that the user can select from based off the number of free slots available to them at their
			//current level.
			weaponStringArrayList = ConstantEquipmentHelper.getCondensedWeaponString();

			//The adapter that recieves the layout type from android and the array creatd by the above function.
			final SimpleAdapter simpleAdapter = new SimpleAdapter(this, weaponStringArrayList, R.layout.weapon_list_item, new String[] { "name", "category" }, new int[] { R.id.weaponListItemName,
					R.id.weaponListItemCategory });

			//Set that adapter!
			weaponDialogAcTextView.setAdapter(simpleAdapter);

			weaponDialogAddButton.setEnabled(false);

			//The amount of letters is needs before it starts auto completing
			weaponDialogAcTextView.setThreshold(1);

			weaponDialogAcTextView.setOnItemClickListener(new OnItemClickListener() {

				@Override
				public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

					//Toast.makeText(getApplicationContext(), "ITEM CLICK", Toast.LENGTH_SHORT).show();

					Map<String, String> temp = new HashMap<String, String>();
					temp = (Map<String, String>) simpleAdapter.getItem(position);

					weaponDialogAcTextView.setText("");

					tempWeapon = ConstantEquipmentHelper.getWeaponObject(temp.get("category"), temp.get("name"), character.info.getBonusSize());

					weaponDialogName.setText(tempWeapon.getName());
					weaponDialogType.setText(tempWeapon.getWeaponStyle());
					weaponDialogDamage.setText(tempWeapon.getDamage());
					weaponDialogCritical.setText(tempWeapon.getCritical());
					weaponDialogRange.setText(tempWeapon.getRange());
					weaponDialogWeight.setText(tempWeapon.getWeight());
					weaponDialogCost.setText(tempWeapon.getValue());

					//					character.equipment.add(tempWeapon);

					weaponDialogAddButton.setEnabled(true);

					InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
					imm.hideSoftInputFromWindow(weaponDialogCost.getWindowToken(), 0);

				}
			});

			weaponDialogAddButton.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {

					if (tempWeapon.isRanged())
						tempWeapon.calculateAndSetAttackAndRollBonus(character.characterClass.getRangedAttackBonusString(), character.abilities.getSTRMOD(), character.abilities.getDEXMOD());
					else
						tempWeapon.calculateAndSetAttackAndRollBonus(character.characterClass.getMeleeAttackBonusString(), character.abilities.getSTRMOD(), character.abilities.getDEXMOD());

					character.equipment.add(tempWeapon);

					weaponAdapter.addWeapon(tempWeapon);

					tempWeapon = null;

					weaponAdapter.notifyDataSetChanged();

					weaponDialog.cancel();
				}
			});

			weaponDialog.show();
		}
		return false;
	}

	@Override
	protected void onPause() {
		super.onPause();

		//Write single character to its own file
		FileHelper.writeSingleCharacter(ConstantHelper.FILE_DIRECTORY + character.getFileIdentifier(), character);

		//Construct a string to save to the ArrayList file object
		int uniqueId = character.getUniqueId();

		FileHelper fh = new FileHelper();
		ArrayList<String> characterListString = fh.getStringCharacterList();

		for (String s : characterListString) {
			if (s.contains(String.valueOf(uniqueId))) {
				int index = characterListString.indexOf(s);
				characterListString.remove(s);
				String tempArray = character.info.getName() + ":" + String.valueOf(character.characterClass.getLevel()) + ":" + character.info.getRace() + ":" + character.characterClass.getClassDescriptionString() + ":"
						+ String.valueOf(character.getUniqueId());

				characterListString.add(index, tempArray);

				break;
			}
		}

	}

	//	@Override
	//	protected void onResume() {
	//		super.onResume();
	//		
	//	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		try {
			if (requestCode == ConstantHelper.REQUEST_CODE_PREPARE_SPELLS) {
				Bundle myResults = data.getExtras();
				boolean prepareButtonPressed = myResults.getBoolean("prepareButtonPressed");

				if (prepareButtonPressed) {
					Character tempCharacter = (Character) myResults.get("character");
					this.character = tempCharacter;
				}

				//TODO: THIS NEEDS TO BE FIXED
				myPager.setCurrentItem(2);

				adapter.notifyDataSetChanged();

				//initSpells(currentSpellBookView);

			}
		} catch (Exception e) {
			Toast.makeText(getApplicationContext(), "Spells were not prepared", Toast.LENGTH_SHORT).show();
		}
	}

	private class MyPagerAdapter extends PagerAdapter {

		public int getCount() {
			int retVal;
			if (character.overallMagicType == ConstantHelper.CHAR_TYPE_MAGIC)
				retVal = 4;
			else
				retVal = 3;

			return retVal;
		}

		public int getItemPosition(Object object) {
			return POSITION_NONE;
		}

		public Object instantiateItem(View collection, int position) {

			View newView = null;
			if (character.overallMagicType == ConstantHelper.CHAR_TYPE_MAGIC) {
				switch (position) {
				case 0: {
					newView = initializeItemScreen(collection);
					//Initialize Items view
					break;
				}
				case 1: {
					//Initialize BattleScreen view
					newView = initBattleScreen(collection);
					break;
				}
				case 2: {
					//Initialize SpellBook view
					newView = initSpells(collection, currentSpellBookView);
					break;
				}
				case 3: {
					//Initialize Weapons view
					newView = initializeWeaponScreen(collection);
					break;
				}
				}
			} else //NOT MAGICAL CHARACTER:
			{
				switch (position) {
				case 0: {
					//Initialize Items view
					newView = initializeItemScreen(collection);
					break;
				}
				case 1: {
					//Initialize BattleScreen view
					newView = initBattleScreen(collection);
					break;
				}
				case 2: {
					//Initialize Weapons view
					newView = initializeWeaponScreen(collection);
					break;
				}
				}
			}

			// View view = inflater.inflate(resId, null);

			((ViewPager) collection).addView(newView, 0);

			return newView;

		}

		@Override
		public void destroyItem(View arg0, int arg1, Object arg2) {
			((ViewPager) arg0).removeView((View) arg2);

		}

		@Override
		public void finishUpdate(View arg0) {

		}

		@Override
		public boolean isViewFromObject(View arg0, Object arg1) {
			return arg0 == ((View) arg1);

		}

		@Override
		public void restoreState(Parcelable arg0, ClassLoader arg1) {

		}

		@Override
		public Parcelable saveState() {
			return null;
		}

		@Override
		public void startUpdate(View arg0) {

		}
	}

	//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//
	//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//
	//Beginning of Main_BattleScreen_magic menu code
	//
	//
	//

	//This view is initialized if the character's magic type is normal or special
	/**
	 * 
	 */
	private View initBattleScreen(View collection) {

		//setContentView(R.layout.battle_screen_magic);

		LayoutInflater inflater = (LayoutInflater) collection.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = inflater.inflate(R.layout.battle_screen_magic, null);

		//displayMode = ConstantHelper.DISPLAY_MODE_BATTLE_SCREEN;

		experienceLayout = (LinearLayout) view.findViewById(R.id.LinearLayoutExperience);
		healthBoxLayout = (LinearLayout) view.findViewById(R.id.linearHealthLayout);
		healthBarLayout = (LinearLayout) view.findViewById(R.id.healthBarLinearLayout);
		swipeLayout = (LinearLayout) view.findViewById(R.id.mainSwipeLayout);

		currentHealthTxt = (TextView) view.findViewById(R.id.battleMagicHealthCurrent);
		totalHealthTxt = (TextView) view.findViewById(R.id.battleMagicHealthTotal);

		strTxt = (TextView) view.findViewById(R.id.battlemagicAbilStr);
		dexTxt = (TextView) view.findViewById(R.id.battlemagicAbilDex);
		conTxt = (TextView) view.findViewById(R.id.battlemagicAbilCon);
		intTxt = (TextView) view.findViewById(R.id.battlemagicAbilInt);
		wisTxt = (TextView) view.findViewById(R.id.battlemagicAbilWis);
		chaTxt = (TextView) view.findViewById(R.id.battlemagicAbilCha);

		strModTxt = (TextView) view.findViewById(R.id.battlemagicAbilStrMod);
		dexModTxt = (TextView) view.findViewById(R.id.battlemagicAbilDexMod);
		conModTxt = (TextView) view.findViewById(R.id.battlemagicAbilConMod);
		intModTxt = (TextView) view.findViewById(R.id.battlemagicAbilIntMod);
		wisModTxt = (TextView) view.findViewById(R.id.battlemagicAbilWisMod);
		chaModTxt = (TextView) view.findViewById(R.id.battlemagicAbilChaMod);

		armorClassTxt = (TextView) view.findViewById(R.id.battlemagicArmorClass);

		saveFortTxt = (TextView) view.findViewById(R.id.battleagicFortSave);
		saveReflexTxt = (TextView) view.findViewById(R.id.battlemagicRefSave);
		saveWillTxt = (TextView) view.findViewById(R.id.battlemagicWillSave);

		conciousWarnTxt = (TextView) view.findViewById(R.id.battlemagicConciousState);

		experienceTxt = (TextView) view.findViewById(R.id.battlemagicExpCurrent);

		healthbar = (ProgressBar) view.findViewById(R.id.battlemagicHealthBar);

		experienceTxt = (TextView) view.findViewById(R.id.battlemagicExpCurrent);//battlemagicExpCurrent
		baseExpTxt = (TextView) view.findViewById(R.id.battlemagicExplevelBase);//battlemagicExplevelBase
		maxExpTxt = (TextView) view.findViewById(R.id.battlemagicExplevelMax);//battlemagicExplevelMax
		currentLevelTxt = (TextView) view.findViewById(R.id.battlemagicCurrentLevel);//battlemagicCurrentLevel
		experienceBar = (ProgressBar) view.findViewById(R.id.battlemagicExpBar);

		//Updates all the elements on the battleScreen
		updateBattleScreen();

		experienceLayout.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				final Dialog dialog = new Dialog(BattleScreen.this);
				dialog.setContentView(R.layout.level_up_dialog);
				dialog.setTitle("Add Experience");
				dialog.setCancelable(true);

				final EditText experienceEditText = (EditText) dialog.findViewById(R.id.expEditTxt);
				final Button button1 = (Button) dialog.findViewById(R.id.expButton1);
				final Button button2 = (Button) dialog.findViewById(R.id.expButton2);
				final Button button3 = (Button) dialog.findViewById(R.id.expButton3);
				final Button button4 = (Button) dialog.findViewById(R.id.expButton4);
				final Button button5 = (Button) dialog.findViewById(R.id.expButton5);
				final Button button6 = (Button) dialog.findViewById(R.id.expButton6);
				final Button button7 = (Button) dialog.findViewById(R.id.expButton7);
				final Button button8 = (Button) dialog.findViewById(R.id.expButton8);
				final Button button9 = (Button) dialog.findViewById(R.id.expButton9);
				final Button button0 = (Button) dialog.findViewById(R.id.expButton0);
				final Button buttonBack = (Button) dialog.findViewById(R.id.expButtonBack);
				final Button buttonClear = (Button) dialog.findViewById(R.id.expButtonClear);
				final ImageButton buttonPlus = (ImageButton) dialog.findViewById(R.id.expAdjustPlus);
				final ImageButton buttonMinus = (ImageButton) dialog.findViewById(R.id.expAdjustMinus);

				buttonPlus.setEnabled(false);
				buttonMinus.setEnabled(false);

				experienceEditText.setText("");

				button1.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						experienceEditText.append("1");
						if (experienceEditText.getText().length() == 0) {
							buttonPlus.setEnabled(false);
							buttonMinus.setEnabled(false);
						} else {
							buttonPlus.setEnabled(true);
							buttonMinus.setEnabled(true);
						}
					}
				});
				button2.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						experienceEditText.append("2");
						if (experienceEditText.getText().length() == 0) {
							buttonPlus.setEnabled(false);
							buttonMinus.setEnabled(false);
						} else {
							buttonPlus.setEnabled(true);
							buttonMinus.setEnabled(true);
						}
					}
				});
				button3.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						experienceEditText.append("3");
						if (experienceEditText.getText().length() == 0) {
							buttonPlus.setEnabled(false);
							buttonMinus.setEnabled(false);
						} else {
							buttonPlus.setEnabled(true);
							buttonMinus.setEnabled(true);
						}
					}
				});
				button4.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						experienceEditText.append("4");
						if (experienceEditText.getText().length() == 0) {
							buttonPlus.setEnabled(false);
							buttonMinus.setEnabled(false);
						} else {
							buttonPlus.setEnabled(true);
							buttonMinus.setEnabled(true);
						}
					}
				});
				button5.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						experienceEditText.append("5");
						if (experienceEditText.getText().length() == 0) {
							buttonPlus.setEnabled(false);
							buttonMinus.setEnabled(false);
						} else {
							buttonPlus.setEnabled(true);
							buttonMinus.setEnabled(true);
						}
					}
				});
				button6.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						experienceEditText.append("6");
						if (experienceEditText.getText().length() == 0) {
							buttonPlus.setEnabled(false);
							buttonMinus.setEnabled(false);
						} else {
							buttonPlus.setEnabled(true);
							buttonMinus.setEnabled(true);
						}
					}
				});
				button7.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						experienceEditText.append("7");
						if (experienceEditText.getText().length() == 0) {
							buttonPlus.setEnabled(false);
							buttonMinus.setEnabled(false);
						} else {
							buttonPlus.setEnabled(true);
							buttonMinus.setEnabled(true);
						}
					}
				});
				button8.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						experienceEditText.append("8");
						if (experienceEditText.getText().length() == 0) {
							buttonPlus.setEnabled(false);
							buttonMinus.setEnabled(false);
						} else {
							buttonPlus.setEnabled(true);
							buttonMinus.setEnabled(true);
						}
					}
				});
				button9.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						experienceEditText.append("9");
						if (experienceEditText.getText().length() == 0) {
							buttonPlus.setEnabled(false);
							buttonMinus.setEnabled(false);
						} else {
							buttonPlus.setEnabled(true);
							buttonMinus.setEnabled(true);
						}
					}
				});
				button0.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						experienceEditText.append("0");
						if (experienceEditText.getText().length() == 0) {
							buttonPlus.setEnabled(false);
							buttonMinus.setEnabled(false);
						} else {
							buttonPlus.setEnabled(true);
							buttonMinus.setEnabled(true);
						}
					}
				});
				buttonBack.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						//Removes one character off the end of the string
						String newStr = experienceEditText.getText().toString();
						if (newStr.length() > 0) {
							newStr = newStr.substring(0, newStr.length() - 1);
							//Set the text to the new string
							experienceEditText.setText(newStr);
						}
						if (experienceEditText.getText().length() == 0) {
							buttonPlus.setEnabled(false);
							buttonMinus.setEnabled(false);
						} else {
							buttonPlus.setEnabled(true);
							buttonMinus.setEnabled(true);
						}
					}
				});
				buttonClear.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {

						//Removes all the text
						experienceEditText.setText("");
						buttonPlus.setEnabled(false);
						buttonMinus.setEnabled(false);
					}
				});
				buttonPlus.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						//This adds to the character's experience points
						character.info.addToExperiencePoints(Integer.parseInt(experienceEditText.getText().toString()));

						//Cancel the dialog and check if the character needs leveling up
						dialog.cancel();

						//In either case, the screen will be updated. 
						//Either through the levelUpCharacter function or through theupdate BattleScreen Function
						if (character.info.getExperience() > character.info.getExpToNextLevel(character.characterClass.getLevel()))
							levelUpCharacter();
						else
							updateProgressBars();
					}

				});

				buttonMinus.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						{
							//This adds to the character's experience points
							character.info.subtractFromExperiencePoints(Integer.parseInt(experienceEditText.getText().toString()));

							//Cancel the dialog
							dialog.cancel();

							//Update the experience bars
							updateProgressBars();
						}
					}
				});

				dialog.show();
			}
		});

		healthBoxLayout.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				manualHealthEntry = false;

				final Dialog dialog = new Dialog(BattleScreen.this);
				dialog.setContentView(R.layout.health_adjust_dialog);
				dialog.setTitle("Adjust your health");
				dialog.setCancelable(true);

				final EditText healthEditText = (EditText) dialog.findViewById(R.id.healthadjustEditTxt);
				final Button button1 = (Button) dialog.findViewById(R.id.healthadjustButton1);
				final Button button2 = (Button) dialog.findViewById(R.id.healthadjustButton2);
				final Button button3 = (Button) dialog.findViewById(R.id.healthadjustButton3);
				final Button button4 = (Button) dialog.findViewById(R.id.healthadjustButton4);
				final Button button5 = (Button) dialog.findViewById(R.id.healthadjustButton5);
				final Button button6 = (Button) dialog.findViewById(R.id.healthadjustButton6);
				final Button button7 = (Button) dialog.findViewById(R.id.healthadjustButton7);
				final Button button8 = (Button) dialog.findViewById(R.id.healthadjustButton8);
				final Button button9 = (Button) dialog.findViewById(R.id.healthadjustButton9);
				final Button button0 = (Button) dialog.findViewById(R.id.healthadjustButton0);
				final Button buttonDone = (Button) dialog.findViewById(R.id.healthadjustButtonDone);
				final Button buttonBack = (Button) dialog.findViewById(R.id.healthadjustButtonBack);
				final Button buttonClear = (Button) dialog.findViewById(R.id.healthadjustButtonClear);

				final ImageButton plusButton = (ImageButton) dialog.findViewById(R.id.healthadjustPlus);
				final ImageButton minusButton = (ImageButton) dialog.findViewById(R.id.healthadjustMinus);

				healthEditText.setText("1");
				healthEditText.setFocusable(false);

				button1.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						if (!manualHealthEntry)
							healthEditText.setText("1");
						else
							healthEditText.append("1");
						manualHealthEntry = true;
					}
				});
				button2.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						if (!manualHealthEntry)
							healthEditText.setText("2");
						else
							healthEditText.append("2");
						manualHealthEntry = true;
					}
				});
				button3.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						if (!manualHealthEntry)
							healthEditText.setText("3");
						else
							healthEditText.append("3");
						manualHealthEntry = true;
					}
				});
				button4.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						if (!manualHealthEntry)
							healthEditText.setText("4");
						else
							healthEditText.append("4");
						manualHealthEntry = true;
					}
				});
				button5.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						if (!manualHealthEntry)
							healthEditText.setText("5");
						else
							healthEditText.append("5");
						manualHealthEntry = true;
					}
				});
				button6.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						if (!manualHealthEntry)
							healthEditText.setText("6");
						else
							healthEditText.append("6");
						manualHealthEntry = true;
					}
				});
				button7.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						if (!manualHealthEntry)
							healthEditText.setText("7");
						else
							healthEditText.append("7");
						manualHealthEntry = true;
					}
				});
				button8.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						if (!manualHealthEntry)
							healthEditText.setText("8");
						else
							healthEditText.append("8");
						manualHealthEntry = true;
					}
				});
				button9.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						if (!manualHealthEntry)
							healthEditText.setText("9");
						else
							healthEditText.append("9");
						manualHealthEntry = true;
					}
				});
				button0.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						if (!manualHealthEntry)
							healthEditText.setText("0");
						else
							healthEditText.append("0");
						manualHealthEntry = true;
					}
				});
				buttonBack.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						//Removes one character off the end of the string
						String newStr = healthEditText.getText().toString();
						if (newStr.length() > 0) {
							newStr = newStr.substring(0, newStr.length() - 1);
							//Set the text to the new string
							healthEditText.setText(newStr);
						} else
							manualHealthEntry = false;
					}
				});
				buttonClear.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {

						//Removes all the text
						healthEditText.setText("");
						manualHealthEntry = false;
					}
				});

				//Increases the current health of the player by the amount entered by the user on the dialog box.
				plusButton.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						try {
							int curHealth = character.info.getCurrentHP();
							int maxHealth = character.info.getTotalHP();

							int maxNum = maxHealth - curHealth;
							if (character.info.getCurrentHP() < character.info.getTotalHP()) {
								if (Integer.parseInt(healthEditText.getText().toString()) <= maxNum && healthEditText.getText().length() > 0) {
									int healthChange = Integer.parseInt(healthEditText.getText().toString());
									character.info.adjustHealth(healthChange);
									if (manualHealthEntry)
										dialog.cancel();
									updateBattleScreen();
								}
							} else {
								Toast.makeText(BattleScreen.this, "Invalid Entry made", Toast.LENGTH_LONG);
							}
						} catch (NumberFormatException e) {
							Toast.makeText(BattleScreen.this, "No number entered", Toast.LENGTH_LONG);
						}

					}
				});

				//On long Click resets the player's health to full.
				plusButton.setOnLongClickListener(new OnLongClickListener() {

					@Override
					public boolean onLongClick(View v) {
						character.info.setCurrentHP(character.info.getTotalHP());
						dialog.cancel();
						updateBattleScreen();
						return true;
					}
				});

				//Decreases the current health of the player by the amount entered by the user on the dialog box.
				minusButton.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						try {

							int curHealth = character.info.getCurrentHP();

							int minNum = Math.abs(curHealth - (-10));

							if (character.info.getCurrentHP() > -10) {
								if (Integer.parseInt(healthEditText.getText().toString()) <= minNum && healthEditText.getText().length() > 0) {
									int healthChange = Integer.parseInt(healthEditText.getText().toString());
									character.info.adjustHealth(-(healthChange));
									if (manualHealthEntry)
										dialog.cancel();
									updateBattleScreen();
								}
							} else {
								Toast.makeText(BattleScreen.this, "Invalid Entry made", Toast.LENGTH_LONG);
							}
						} catch (NumberFormatException e) {
							Toast.makeText(BattleScreen.this, "No number entered", Toast.LENGTH_LONG);
						}

					}
				});

				buttonDone.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						dialog.cancel();
					}
				});

				dialog.show();
			}
		});
		return view;
	}

	/**
	 * This function will initiate the level up process:
	 * 
	 * 1: Notify the user they have leveled up
	 * 
	 * 2: Ask them how much health to add to their chracter's current health
	 * total
	 * 
	 * 3: call the Character.levelUp function
	 * 
	 */
	public void levelUpCharacter() {

		//This dialog will get the character's health increase
		final Dialog dialog = new Dialog(BattleScreen.this);
		dialog.setContentView(R.layout.level_up_health);
		dialog.setTitle("Level up!");
		dialog.setCancelable(false);

		//Bind some variables to the views in the dialog

		levelupSeekBar = (SeekBar) dialog.findViewById(R.id.levelupSeekBar);
		levelupAmountTxt = (TextView) dialog.findViewById(R.id.levelupAmountTxt);
		levelupHitDieTxt = (TextView) dialog.findViewById(R.id.levelupHitDieTxt);
		levelupButton = (Button) dialog.findViewById(R.id.levelUpSubmitButton);

		//Find the hit die and assign it to the text for the user's convenience
		int hitDie = character.characterClass.getHitDieForClass(character.characterClass.getBeginningClass());

		levelupHitDieTxt.setText("Hit die: 1d" + String.valueOf(hitDie));
		levelupAmountTxt.setText("1 + " + character.abilities.getCONMOD() + " health");

		//Set the max the bar can go (hit die)
		levelupSeekBar.setMax(hitDie);

		//Initialize at 1
		levelupSeekBar.setProgress(1);
		levelupSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

			//When the progress changes (drags the slider), update the text view
			@Override
			public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
				levelupSeekBar.setProgress(progress);
				levelupAmountTxt.setText(String.valueOf(progress) + " + " + character.abilities.getCONMOD() + " health");

			}

			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {
			}

			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {
			}
		});

		levelupButton.setOnClickListener(new OnClickListener() {

			//When a health to increase is determined and the button is clicked, Add it to the character's health
			//And initiate the levelup function for the character.
			@Override
			public void onClick(View v) {
				int healthAmt = levelupSeekBar.getProgress();
				returnHealth = healthAmt;
				character.levelUp(returnHealth, character.characterClass.getBeginningClass());
				dialog.cancel();
				updateBattleScreen();
				adapter.notifyDataSetChanged();
			}
		});

		dialog.show();
	}

	/**
	 * Updates the battleScreen for magic user.
	 */
	private void updateBattleScreen() {

		//Sets all the text views
		strTxt.setText(String.valueOf(character.abilities.getSTR()));
		dexTxt.setText(String.valueOf(character.abilities.getDEX()));
		conTxt.setText(String.valueOf(character.abilities.getCON()));
		intTxt.setText(String.valueOf(character.abilities.getINT()));
		wisTxt.setText(String.valueOf(character.abilities.getWIS()));
		chaTxt.setText(String.valueOf(character.abilities.getCHA()));

		strModTxt.setText(getModSign(character.abilities.getSTRMOD()));
		dexModTxt.setText(getModSign(character.abilities.getDEXMOD()));
		conModTxt.setText(getModSign(character.abilities.getCONMOD()));
		intModTxt.setText(getModSign(character.abilities.getINTMOD()));
		wisModTxt.setText(getModSign(character.abilities.getWISMOD()));
		chaModTxt.setText(getModSign(character.abilities.getCHAMOD()));

		armorClassTxt.setText(String.valueOf(character.info.getArmorClass()));

		saveFortTxt.setText(getModSign(character.characterClass.getSavingThrowFortitude()));
		saveReflexTxt.setText(getModSign(character.characterClass.getSavingThrowReflex()));
		saveWillTxt.setText(getModSign(character.characterClass.getSavingThrowWill()));

		currentHealthTxt.setText(String.valueOf(character.info.getCurrentHP()));
		totalHealthTxt.setText(String.valueOf(character.info.getTotalHP()));

		updateProgressBars();
	}

	/**
	 * Gets the appropriate character '+' or '-' depending on the number
	 * 
	 * @param modifier
	 * @return
	 */
	private String getModSign(int modifier) {
		String mod = String.valueOf(modifier);
		String retStr;

		if (modifier > 0)
			retStr = "+" + mod;
		else if (modifier == 0)
			retStr = "  " + mod;
		else
			retStr = "- " + Math.abs(Integer.valueOf(mod));
		return retStr;
	}

	public void updateProgressBars() {

		//Gets the base score for the level the character is currently at
		int levelBase = character.info.getExpToNextLevel(character.characterClass.getLevel() - 1);

		//Gets the current experience of the character 
		int currentExp = character.info.getExperience();

		//Gets the absolute point total needed to level up.
		int nextLevelPointTotal = character.info.getExpToNextLevel(character.characterClass.getLevel());

		if (character.info.getConciousState() == 2)
			conciousWarnTxt.setText("");
		else if (character.info.getConciousState() == 0)
			conciousWarnTxt.setText("DEAD");
		else
			conciousWarnTxt.setText("UNCONCIOUS");

		experienceTxt.setText(String.valueOf(currentExp));
		baseExpTxt.setText(String.valueOf(levelBase));
		maxExpTxt.setText(String.valueOf(nextLevelPointTotal));
		currentLevelTxt.setText("Level: " + String.valueOf(character.characterClass.getLevel()));

		//Set up the progress bar to reflect the changes
		experienceBar.setMax(nextLevelPointTotal - levelBase);
		healthbar.setMax(character.info.getTotalHP());
		healthbar.setVisibility(View.VISIBLE);
		experienceBar.setVisibility(View.VISIBLE);

		healthbar.setProgress(character.info.getCurrentHP());
		experienceBar.setProgress(currentExp - levelBase);
	}

	//
	//
	//
	//End of Main_BattleScreen_magic menu code
	//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//
	//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//

	//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//
	//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//
	//Beginning of magic_spells_menu code
	//
	//
	//

	private View initSpells(View collection, int spellBookPosition) {

		LayoutInflater inflater = (LayoutInflater) collection.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = inflater.inflate(R.layout.magic_spells_menu, null);

		currentSpellBookView = spellBookPosition;

		spellsTitleText = (TextView) view.findViewById(R.id.spellsTitleText);
		spellsTitleText.setText(ConstantHelper.classIntToString(spellBookPosition) + " Spells");
		//
		magicLinearLayout = (LinearLayout) view.findViewById(R.id.spellLinearLayout);

		//This adapter handles the expandable list that is displayed
		spellListAdapter = new SpellExpandableListAdapter();

		//This function gets the spells for the character and properly arranges them to be displayed in the dropdown list
		spellListAdapter.setSpellArrays();

		//Set list to the ExpandableListView
		list = (ExpandableListView) view.findViewById(R.id.list);
		fillerList = (ExpandableListView) view.findViewById(R.id.fillerExpandableList);

		//Sets adapter..??
		list.setAdapter(spellListAdapter);

		//Removes the dropdown icon
		list.setGroupIndicator(null);

		//This for loop espands the group elements the user had expanded when
		//they left the spell view to visit another. 
		for (int i = 0; i < spellListAdapter.getGroupCount(); i++) {
			if (character.info.getGroupIsExpandedElement(i) == 1)
				list.expandGroup(i);
		}

		//Long clicking the group
		list.setOnLongClickListener(new OnLongClickListener() {

			@Override
			public boolean onLongClick(View v) {
				Log.d("CHAR", "LONG GROUP");
				return true;
			}
		});

		list.setOnGroupExpandListener(new OnGroupExpandListener() {

			@Override
			public void onGroupExpand(int groupPosition) {
				character.info.setGroupIsExpandedElement(groupPosition, 1);
			}
		});
		list.setOnGroupCollapseListener(new OnGroupCollapseListener() {

			@Override
			public void onGroupCollapse(int groupPosition) {
				character.info.setGroupIsExpandedElement(groupPosition, 0);
			}
		});

		return view;
	}

	//This class handles the setting and viewing of the group and child elements of the expandable list
	public class SpellExpandableListAdapter extends BaseExpandableListAdapter {

		//The array containing the spells remaining 
		int[] groupArray;

		//Get the number of spell levels that character has achieved
		int numSpellLevels = character.characterClass.getMaxSpellLevelForSpecificClass(currentSpellBookView);

		//Used to calculate the total number of group array elements to draw
		int totalLevel;

		private String[] groupData;

		private String[][] childrenData;

		//Constructor FTW
		public SpellExpandableListAdapter() {
		}

		/**
		 * This wonderful function manages to pull all the character's spell
		 * information and turn it into ledgable, array structured, data that
		 * can be used for the display and interaction of said spells
		 */
		public void setSpellArrays() {

			inflater = (LayoutInflater) BattleScreen.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

			numSpellLevels = character.characterClass.getMaxSpellLevelForSpecificClass(currentSpellBookView);
			groupArray = character.characterClass.getSpellCastsRemainingForSpecificClass(currentSpellBookView);

			//Iterate through 'dem spells!
			Iterator<String> iter;

			//Used to temporarily hold the spells for that level and store them into the array?
			ArrayList<String> spellsPerLevel = new ArrayList<String>();

			//get the spell list
			ArrayList<Spell> tempSpells = character.getSpells(currentSpellBookView);
			//for every spell level that the character has magic for...

			ArrayList<String> groupArrayListData = new ArrayList<String>();

			childrenData = new String[10][1];

			//TODO: THIS IS MESSY! FIX IT!

			if (character.characterClass.getCharacterMagicType(currentSpellBookView) == ConstantHelper.CHAR_TYPE_NORMAL_MAGIC) {
				childrenData = getNormalMagicChildArrayList(numSpellLevels);
				groupData = getNormalMagicGroupArrayList(numSpellLevels);
			} else {
				//Loop through each spell level for the character
				for (int i = 0; i < numSpellLevels; i++) {
					if (groupArray[i] == 1)
						groupArrayListData.add("Level " + i + ":" + groupArray[i] + " cast remaining");
					else
						groupArrayListData.add("Level " + i + ":" + groupArray[i] + " casts remaining");
					for (Spell s : tempSpells) {
						//Get all the 0 level spells and put their name in an ArrayList
						if (s.getSpellLevel() == i) {
							spellsPerLevel.add(s.getName());
						}
					}
					//Make iterator to loop through the arrayList and turn it into a String[] array
					iter = spellsPerLevel.iterator();

					//Create a variable length array based on the number of spells in that spell level range
					String[] tempArray = new String[spellsPerLevel.size()];

					//For loop that does the assigning from ArrayList to String[]
					for (int j = 0; j < spellsPerLevel.size(); j++) {
						String item = iter.next();
						tempArray[j] = item;
					}
					//Assign the childData[] to tempArray
					childrenData[i] = tempArray;

					//Reset the ArrayList for use on the next go around
					spellsPerLevel.clear();
				}

				String[] groupStringArray = new String[groupArrayListData.size()];
				int count = 0;
				for (String s : groupArrayListData) {
					groupStringArray[count] = s;
					count++;
				}

				//Gets rid of excess slots
				for (int i = numSpellLevels; i < 10; i++) {
					childrenData[i] = null;
				}
				groupData = groupStringArray;
			}
			spellListAdapter.notifyDataSetChanged();
		}

		private String[][] getNormalMagicChildArrayList(int numSpellLevels2) {
			ArrayList<String> tempSpellsList = new ArrayList<String>();
			String[][] retArray = new String[10][1];
			boolean[][] hasBeenCastArray = new boolean[10][10];
			for (int i = 0; i < numSpellLevels2; i++) {
				for (SpellListItem sli : character.characterClass.getSpellListItemArray()) {
					if (sli.getLevel() == i) {
						for (int k = 0; k < sli.getCount(); k++) {
							tempSpellsList.add(sli.getName());
						}
					}
				}
				Collections.sort(tempSpellsList);
				//Make iterator to loop through the arrayList and turn it into a String[] array
				Iterator<String> iter = tempSpellsList.iterator();

				//Create a variable length array based on the number of spells in that spell level range
				String[] tempArray = new String[tempSpellsList.size()];

				//For loop that does the assigning from ArrayList to String[]
				for (int j = 0; j < tempSpellsList.size(); j++) {
					String item = iter.next();
					tempArray[j] = item;
				}
				tempSpellsList.clear();
				//Assign the childData[] to tempArray
				retArray[i] = tempArray;
			}

			return retArray;
		}

		private String[] getNormalMagicGroupArrayList(int numSpellLevels2) {
			String[] returnArray = new String[numSpellLevels2];
			for (int i = 0; i < numSpellLevels2; i++) {
				returnArray[i] = "Level " + i + ": ";
			}
			return returnArray;
		}

		//The temporary holder for the child view. Used for stuff like setting button listeners
		public class ChildViewHolder {
			TextView txtCharName;
			Button castButton;
		}

		//See above comment
		public class GroupViewHolder {
			TextView txtSpellLevel;
			TextView txtSpellRemaining;
			ImageView imageArrow;
		}

		//Gets the child data at the specified position
		public Object getChild(int groupPosition, int childPosition) {
			return childrenData[groupPosition][childPosition];
		}

		//Gets the id of the child
		public long getChildId(int groupPosition, int childPosition) {
			return childPosition;
		}

		//Gets the number of children in the list
		public int getChildrenCount(int groupPosition) {
			return childrenData[groupPosition].length;
		}

		//This part actually is very useful.. Does stuff like Sets data pulled from the adapter, and sets onclickListeners
		//Also an onFling listener here incase there needs to be scrolling back to the main BattleScreen
		public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {

			//Sets the groupPosition so it can be used by the clickListener
			final int groupPos = groupPosition;
			final int childPos = childPosition;

			//I do not completely understand all of this...
			final ChildViewHolder holder;
			if (convertView == null) {
				//Sets up a new holder to temporaraly hold the listeners that will be assigned to the binded variables
				holder = new ChildViewHolder();
				convertView = inflater.inflate(R.layout.spell_child_row, null);

				//Find the IDs! Find them!!!!
				holder.txtCharName = (TextView) convertView.findViewById(R.id.battlemagicSpellChildTxt);
				holder.castButton = (Button) convertView.findViewById(R.id.battlemagicSpellChildButton);

				//"Sets the tag associated with this view. A tag can be used
				//to mark a view in its hierarchy and does not have to be unique within the hierarchy."
				convertView.setTag(holder);
			} else {
				holder = (ChildViewHolder) convertView.getTag();
			}
			String spellName = childrenData[groupPosition][childPosition];

			holder.txtCharName.setText(spellName);
			holder.castButton.setText("Cast");

			//For normal magic users
			if (character.characterClass.getSpeficficCharacterClassMagicType(currentSpellBookView) == ConstantHelper.CHAR_TYPE_NORMAL_MAGIC) {
				if (character.characterClass.gethasBeenCastArrayElement(groupPos, childPos) == false) {
					holder.castButton.setEnabled(true);
				} else
					holder.castButton.setEnabled(false);
			} else {

				//Disables the casting of the spell if out of casts for that group
				// Get the max number of spell levels it can look at
				int maxLevel = character.characterClass.getMaxSpellLevelForSpecificClass(currentSpellBookView);
				//Get the remaining casts for that character
				int[] castsRemaining = character.characterClass.getSpellCastsRemainingForSpecificClass(currentSpellBookView); // Check if the curent level is out (use parent group)
				boolean foundCastable = false;
				if (castsRemaining[groupPosition] <= 0) {

					//if the current one is out
					//check the higher levels if the current level can use the casts of an upper level
					for (int i = groupPosition; i <= maxLevel; i++) {
						if (castsRemaining[i] > 0) {
							foundCastable = true;
						}
					}
					//else (it can not find and usable upper level casts)
				} else
					foundCastable = true;

				if (foundCastable == false)
					holder.castButton.setEnabled(false);
				else
					holder.castButton.setEnabled(true);
			}

			//Button listeners always good...
			holder.castButton.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {

					//If character is special magic type...
					if (character.characterClass.getSpeficficCharacterClassMagicType(currentSpellBookView) == ConstantHelper.CHAR_TYPE_SPECIAL_MAGIC) {
						//Disables the casting of the spell if out of casts for that group
						// Get the max number of spell levels it can look at
						int maxLevel = character.characterClass.getMaxSpellLevelForSpecificClass(currentSpellBookView);
						//Get the remaining casts for that character
						int[] castsRemaining = character.characterClass.getSpellCastsRemainingForSpecificClass(currentSpellBookView);
						// Check if the curent level is out (use parent group)
						if (castsRemaining[groupPos] <= 0) {
							//boolean foundCastable = false;

							//if the current one is out
							//check the higher levels if the current level can use the casts of an upper level
							for (int i = groupPos; i <= maxLevel; i++) {
								if (castsRemaining[i] > 0) {
									character.characterClass.decrementSpellsRemaining(currentSpellBookView, i);
									break;
								}
							}
						} else {
							character.characterClass.decrementSpellsRemaining(currentSpellBookView, groupPos);
						}
						setSpellArrays();
						spellListAdapter.notifyDataSetChanged();

					} else { //Is normal magic that needs to disable the button when clicked
						holder.castButton.setEnabled(false);
						character.characterClass.setHasBeenCastArrayElement(groupPos, childPos, true);
						//character.characterClass.decrementSpellsRemaining(currentSpellBookView, groupPos);
					}
				}
			});

			holder.txtCharName.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					String spellname = holder.txtCharName.getText().toString();
					Spell tempSpell = character.getSpellBasedOnName(spellname, currentSpellBookView);
					if (tempSpell != null) {
						FileHelper fh = new FileHelper();
						tempSpell = fh.getSpellInformationBasedOnName(spellname, BattleScreen.this, currentSpellBookView);
					}
					StringBuffer sb = new StringBuffer();
					for (int i = 1; i < tempSpell.getSpellProperties().size(); i++) {
						sb.append(tempSpell.getConcatinatedHtmlProperty(i));
					}
					final Dialog dialog = new Dialog(BattleScreen.this);
					dialog.setContentView(R.layout.prepare_spell_about_spell);
					dialog.setTitle(tempSpell.getSpellName());
					dialog.setCancelable(true);

					TextView spellInformaion = (TextView) dialog.findViewById(R.id.prepareSpellsTextView);
					Button viewSpellCancel = (Button) dialog.findViewById(R.id.prepSpellCancel);

					spellInformaion.setText(Html.fromHtml(sb.toString()));

					viewSpellCancel.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							dialog.cancel();
						}
					});

					dialog.show();
				}
			});

			holder.txtCharName.setOnLongClickListener(new OnLongClickListener() {

				@Override
				public boolean onLongClick(View v) {

					if (character.characterClass.getCharacterMagicType(currentSpellBookView) == ConstantHelper.CHAR_TYPE_NORMAL_MAGIC)
						return false;
					AlertDialog.Builder dialog = new AlertDialog.Builder(BattleScreen.this);
					dialog.setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int id) {
							String spellName = holder.txtCharName.getText().toString();
							character.removeSpellFromClass(spellName, currentSpellBookView);

							setSpellArrays();
							spellListAdapter.notifyDataSetChanged();
						}
					}).setNegativeButton("No", new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int id) {
							dialog.cancel();
						}

					}).setTitle("Remove this Spell?");

					AlertDialog alert = dialog.create();
					alert.show();

					return false;
				}
			});

			return convertView;
		}

		public Object getGroup(int groupPosition) {
			return groupData[groupPosition];
		}

		public int getGroupCount() {
			return groupData.length;
		}

		public long getGroupId(int groupPosition) {
			return groupPosition;
		}

		public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {

			GroupViewHolder holder;
			if (convertView == null) {
				holder = new GroupViewHolder();
				convertView = inflater.inflate(R.layout.spell_group_row, null);

				holder.imageArrow = (ImageView) convertView.findViewById(R.id.battleMagicSpellRowArrowImage);
				holder.txtSpellLevel = (TextView) convertView.findViewById(R.id.battlemagicSpellRowLevelTxt);
				holder.txtSpellRemaining = (TextView) convertView.findViewById(R.id.battlemagicSpellRowRemainingTxt);

				convertView.setTag(holder);
			} else {
				holder = (GroupViewHolder) convertView.getTag();
			}
			String groupInfo = groupData[groupPosition];

			String delimiter = "\\:";
			String[] split = groupInfo.split(delimiter);

			holder.txtSpellLevel.setText(split[0]);
			holder.txtSpellRemaining.setText(split[1]);
			if (character.info.getGroupIsExpandedElement(groupPosition) == 1)
				holder.imageArrow.setImageResource(R.drawable.arrow_down);
			else
				holder.imageArrow.setImageResource(R.drawable.arrow_right);

			if (getChildrenCount(groupPosition) == 0)
				holder.imageArrow.setVisibility(View.INVISIBLE);
			else
				holder.imageArrow.setVisibility(View.VISIBLE);

			return convertView;
		}

		public boolean hasStableIds() {
			return false;
		}

		public boolean isChildSelectable(int groupPosition, int childPosition) {
			return false;
		}

	}

	//
	//
	//
	//End of magic_spells_menu code
	//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//
	//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//

	//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//
	//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//
	//Beginning of item_screen code
	//
	//
	//

	public View initializeItemScreen(View collection) {

		LayoutInflater inflater = (LayoutInflater) collection.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = inflater.inflate(R.layout.item_screen, null);

		itemListView = (ExpandableListView) view.findViewById(R.id.itemListView);

		itemAdapter = new ItemAdapter(this, character.items);

		itemListView.setAdapter(itemAdapter);

		itemListView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
				Log.d("CHAR", "LIST ITEM CKICKED");
				//character.unequipAllWeapons();

			};
		});
		return view;
	}

	public class ItemListCustomAdapter extends BaseAdapter {
		private ArrayList<Item> itemList;
		private LayoutInflater inflater;

		public ItemListCustomAdapter(Context context, ArrayList<Equipment> equipment) {
			inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

			itemList = new ArrayList<Item>();

			for (Equipment e : equipment) {
				if (e instanceof Item) {
					Item tempItem = (Item) e;
					if (tempItem.isPermanent())
						itemList.add(tempItem);
				}
			}
		}

		public void addItem(Item item) {
			itemList.add(item);
		}

		public void removeItem(Item item) {
			itemList.remove(item);
		}

		public Item getEquipmentItemObject(Item item) {
			Item retItem = null;
			for (Equipment e : itemList) {
				if (e instanceof Item) {
					if (e.equals(item))
						retItem = (Item) e;
				}
			}
			return retItem;
		}

		@Override
		public int getCount() {
			return itemList.size();
		}

		@Override
		public Equipment getItem(int arg0) {
			return itemList.get(arg0);
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

		public ArrayList<Item> getItemList() {
			return itemList;
		}

		class PermHolder {
			TextView itemName;
			TextView itemDescription;
		}

		class TempHolder {
			TextView itemName;
			TextView itemType;
			ProgressBar itemProgress;
			Button itemCastButton;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			final int finalPos = position;

			PermHolder permHolder = new PermHolder();
			TempHolder tempHolder = new TempHolder();

			Item item = (Item) itemList.get(position);
			if (convertView == null) {
				//If the item type is permanent:
				if (item.isPermanent() == true) {
					convertView = inflater.inflate(R.layout.list_item_row_perm, null);

					permHolder.itemName = (TextView) convertView.findViewById(R.id.itemRowPermName);
					permHolder.itemDescription = (TextView) convertView.findViewById(R.id.itemRowPermDescription);
					convertView.setTag(permHolder);
				} else {
					convertView = inflater.inflate(R.layout.list_item_row_temp, null);

					tempHolder.itemType = (TextView) convertView.findViewById(R.id.itemRowTempType);
					tempHolder.itemName = (TextView) convertView.findViewById(R.id.itemRowTempName);
					tempHolder.itemProgress = (ProgressBar) convertView.findViewById(R.id.itemRowTempProgressBar);
					tempHolder.itemCastButton = (Button) convertView.findViewById(R.id.itemRowTempCastButton);
					convertView.setTag(tempHolder);
				}
			} else {
				if (item.isPermanent() == true) {
					permHolder = (PermHolder) convertView.getTag();
					permHolder.itemDescription.setText(item.getDescription());
					permHolder.itemName.setText(item.getName());
				} else {
					tempHolder = (TempHolder) convertView.getTag();
					tempHolder.itemType.setText(item.getItemType());
					tempHolder.itemName.setText(item.getName());
					tempHolder.itemProgress.setMax(item.getMaxUses());
					tempHolder.itemProgress.setProgress(item.getUsesRemaining());
					tempHolder.itemCastButton.setText(item.getUsesRemaining());
					tempHolder.itemCastButton.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							Item item = (Item) getItem(finalPos);
							character.decrementUsesForItem(item);
							itemAdapter.notifyDataSetChanged();
						}
					});
				}
			}
			return convertView;
		}
	}

	//
	//
	//
	//End of item_screen code
	//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//
	//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//

	//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//
	//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//
	//Beginning of weapon_screen code
	//
	//
	//

	public View initializeWeaponScreen(View collection) {

		inflater = (LayoutInflater) collection.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = inflater.inflate(R.layout.weapon_screen, null);

		weaponScreenName = (TextView) view.findViewById(R.id.weaponScreenName);
		weaponScreenAttack = (TextView) view.findViewById(R.id.weaponScreenAttack);
		weaponScreenDamage = (TextView) view.findViewById(R.id.weaponScreenDamage);
		weaponScreenCritical = (TextView) view.findViewById(R.id.weaponScreenCritical);
		weaponScreenRange = (TextView) view.findViewById(R.id.weaponScreenRange);
		//weaponScreenWeight = (TextView) view.findViewById(R.id.weaponScreenWeight);

		tempWeapon = character.getActiveWeapon();

		if (tempWeapon != null) {
			weaponScreenName.setText(tempWeapon.getName());
			weaponScreenAttack.setText(tempWeapon.getAttackBonusString());
			weaponScreenDamage.setText(tempWeapon.getDamageBonusString());
			weaponScreenCritical.setText(tempWeapon.getCritical());
			weaponScreenRange.setText(tempWeapon.getRange());
			//weaponScreenWeight.setText(tempWeapon.getWeight());
		}

		weaponListView = (ListView) view.findViewById(R.id.weaponListView);

		weaponAdapter = new WeaponListCustomAdapter(this, character.equipment); //(WeaponViewCustomAdapter) view.findViewById(R.id.weaponListView);

		weaponListView.setAdapter(weaponAdapter);

		weaponListView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

				character.unequipAllWeapons();

				Weapon selectedWeapon = (Weapon) weaponAdapter.getItem(arg2);

				character.equipment.remove(selectedWeapon);

				selectedWeapon.setEquipped(true);

				character.equipment.add(selectedWeapon);

				weaponScreenName.setText(selectedWeapon.getName());
				weaponScreenAttack.setText(selectedWeapon.getAttackBonusString());
				weaponScreenDamage.setText(selectedWeapon.getDamageBonusString());
				weaponScreenCritical.setText(selectedWeapon.getCritical());
				weaponScreenRange.setText(selectedWeapon.getRange());
				//weaponScreenWeight.setText(selectedWeapon.getWeight());
			}
		});

		weaponListView.setOnItemLongClickListener(new OnItemLongClickListener() {

			@Override
			public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

				final int finalPos = arg2;

				AlertDialog.Builder dialog = new AlertDialog.Builder(BattleScreen.this);
				dialog.setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int id) {

						Weapon selectedWeapon = (Weapon) weaponAdapter.getItem(finalPos);
						character.equipment.remove(selectedWeapon);

						weaponAdapter.removeWeapon(selectedWeapon);

						weaponAdapter.notifyDataSetChanged();
					}
				}).setNegativeButton("No", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int id) {
						dialog.cancel();
					}

				}).setTitle("Remove this Weapon?");

				AlertDialog alert = dialog.create();
				alert.show();

				return false;
			}
		});

		return view;

	}
	//
	//
	//End of weapon_screen code
	//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//
	//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//

}